package com.kkd.kkdapp.adapter;

import java.util.List;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.kkd.kkdapp.R;
import com.kkd.kkdapp.activity.NoticeDetailActivity;
import com.kkd.kkdapp.adapter.CreditAdapter.MyOnclick;
import com.kkd.kkdapp.http.entity.InformationDataList;

public class InformationAdapter extends BaseAdapter {

	private List<InformationDataList> mList;
	private Context mContext;

	public InformationAdapter(Context context, List<InformationDataList> mList) {
		this.mList = mList;
		this.mContext = context;
	}

	static class ViewHodler {
		ImageView readstade;
		TextView title;
		TextView time;
		TextView content;
		RelativeLayout item;
	}

	class InTenderClick implements OnClickListener {

		private String id;

		public InTenderClick(String id) {
			this.id = id;

		}

		@Override
		public void onClick(View v) {
			switch (v.getId()) {
			case R.id.item:
				Intent intent = new Intent(mContext, NoticeDetailActivity.class);
				intent.putExtra("id", id);
				mContext.startActivity(intent);
				break;
			}

		}

	}

	@Override
	public int getCount() {
		return mList.size();
	}

	@Override
	public Object getItem(int position) {
		return mList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHodler viewhodler;
		if (convertView == null) {
			convertView = View.inflate(mContext,
					R.layout.information_listview_item, null);
			viewhodler = new ViewHodler();
			viewhodler.readstade = (ImageView) convertView
					.findViewById(R.id.readstade);
			viewhodler.title = (TextView) convertView.findViewById(R.id.title);
			viewhodler.time = (TextView) convertView.findViewById(R.id.time);
			viewhodler.content = (TextView) convertView
					.findViewById(R.id.content);
			viewhodler.item = (RelativeLayout) convertView
					.findViewById(R.id.item);
			convertView.setTag(viewhodler);
		} else {
			viewhodler = (ViewHodler) convertView.getTag();
		}
		viewhodler.title.setTag(position);
		viewhodler.title.setSelected(true);
		viewhodler.title.setText(mList.get(position).getTitle());
		viewhodler.time.setTag(position);
		viewhodler.time.setText(mList.get(position).getPublishDate());
		viewhodler.content.setTag(position);
		viewhodler.content.setText(mList.get(position).getDescription());
		if ("未读".equals(mList.get(position).getStatus())) {
			// viewhodler.readstade.setImageResource(R.drawable.unread_img);
			viewhodler.readstade.setImageResource(R.drawable.read_img);
		} else if ("已读".equals(mList.get(position).getStatus())) {
			viewhodler.readstade.setImageResource(R.drawable.read_img);
		}
		viewhodler.item.setOnClickListener(new InTenderClick(mList
				.get(position).getId()));
		return convertView;
	}
}
